<?php

namespace app\admin\model\air;

use think\Model;
use app\admin\model\air\Charter;
use app\admin\model\Area;


class CharterQuote extends Model
{

    

    

    // 表名
    protected $name = 'air_charter_quote';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'quote_status_text',
        'handle_time_text'
    ];
    

    
    public function getQuoteStatusList()
    {
        return ['1' => __('Quote_status 1'), '2' => __('Quote_status 2'), '3' => __('Quote_status 3'), '4' => __('Quote_status 4')];
    }


    public function getQuoteStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['quote_status']) ? $data['quote_status'] : '');
        $list = $this->getQuoteStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getHandleTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['handle_time']) ? $data['handle_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setHandleTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function cc()
    {
        return $this->belongsTo(Charter::class, 'air_charter_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function scity()
    {
        return $this->belongsTo(Area::class, 'start_area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function ecity()
    {
        return $this->belongsTo(Area::class, 'end_area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
